/**
 * @format
 * @Author: TC
 * @Date: 2021-09-26 13:36:06
 * @Last Modified by: TC
 * @Last Modified time: 2025-05-05 01:45:58
 */

import { sys } from "cc";

//辅助函数类
export namespace nsExtend {
    /**
     * 向数组中插入元素
     * @param t 插入的元素
     * @param a 数组
     */
    export function pushToArr(t: any, a: Array<any>): void {
        var index: number = a.indexOf(t);
        if (index < 0) {
            a.push(t);
        }
    }

    /**
     * 删除数组中的元素
     * @param t 删除的元素
     * @param a 数组
     */
    export function removeFromArr(t: any, a: Array<any>): void {
        var index: number = a.indexOf(t);
        if (index > -1) a.splice(index, 1);
    }

    /**
     * 是否有键盘
     */
    export function hasKeyboard(): boolean {
        return !sys.isMobile;
    }

    /**
     * 深拷贝
     * @param obj 原对象
     */
    export function depthClone(obj: any): any {
        if (obj == undefined || obj == null || "object" != typeof obj) return obj;
        let clone: any = null;
        if (obj instanceof Array) {
            clone = [];
        } else {
            clone = {};
        }
        for (let key in obj) {
            clone[key] = this.depthClone(obj[key]);
        }
        return obj;
    }
}
